Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/compose

Package Overview
Dependencies
Maintainers
25
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/compose

WordPress higher-order components (HOCs).

  • 5.20.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
145K
decreased by-14.54%
Maintainers
25
Weekly downloads
 
Created

What is @wordpress/compose?

@wordpress/compose is a utility library for composing higher-order components (HOCs) in React. It provides a set of functions that help in managing component state, lifecycle, and other common patterns in a more declarative and functional way.

What are @wordpress/compose's main functionalities?

withState

The `withState` HOC is used to add state to a functional component. In this example, `count` is the state variable and `setCount` is the function to update it.

const { withState } = require('@wordpress/compose');
const MyComponent = ({ count, setCount }) => (
  <div>
    <p>{count}</p>
    <button onClick={() => setCount(count + 1)}>Increment</button>
  </div>
);
const EnhancedComponent = withState('count', 'setCount', 0)(MyComponent);

withInstanceId

The `withInstanceId` HOC provides a unique instance ID to each instance of the component. This can be useful for accessibility or for differentiating between multiple instances of the same component.

const { withInstanceId } = require('@wordpress/compose');
const MyComponent = ({ instanceId }) => (
  <div>
    <p>Instance ID: {instanceId}</p>
  </div>
);
const EnhancedComponent = withInstanceId(MyComponent);

compose

The `compose` function is used to combine multiple HOCs into a single HOC. In this example, `withState` and `withInstanceId` are combined to enhance `MyComponent`.

const { compose, withState, withInstanceId } = require('@wordpress/compose');
const MyComponent = ({ count, setCount, instanceId }) => (
  <div>
    <p>Instance ID: {instanceId}</p>
    <p>{count}</p>
    <button onClick={() => setCount(count + 1)}>Increment</button>
  </div>
);
const EnhancedComponent = compose(
  withState('count', 'setCount', 0),
  withInstanceId
)(MyComponent);

Other packages similar to @wordpress/compose

Keywords

FAQs

Package last updated on 16 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc